$( document ).ready(function() {
    $('.treeNodeIcon').dblclick();
    $('.treeNodeIcon').first().dblclick();
var custom_css = "#treeSearch{width:93%;margin:3%}#idFilterHdgTable{display:none}.columnHeader table tbody tr td span{color:green!important}.AccordionFirstPaneHead,.HorizSplitter,.PageContentBodyDiv,.PageContentOuterDiv,.PageWithTabsContentOuterDiv,.PrimaryAccordion,.uberBarMainDiv{background-color:#F5F5F5!important;border:none!important},table.HeaderTopBar *{display:none}.AccordionPaneHead,.HeaderContainer{background-color:red!important}.AnswerCatalogPaneTypeSelector{display:none}.AccordionPane[panename=catalog] .AccordionPaneHead,.AccordionPane[panename=viewList] .AccordionPaneHeaderText{display:none!important}.AccordionPane[panename=viewList] .AccordionPaneHead td:first-child{display:none}#idReportViewToolbar{background-color:#F5F5F5!important}.uberBarMainDiv{background-color:#F5F5F5!important}.HeaderTopBar{display:none!important}"
    
    // styles
    $('head').append('<style>'+custom_css+'</style>');    
    $('.AccordionPaneHeadRoundCorner').css('display','none','important');
    $('table.XUISectionHeadingTable').css('display','none','important');
    
    $('#idAvailableDataAccordion .AccordionFirstPaneHead').append('<input type="text" id="treeSearch" name="treeSearch">');
    
    $( "#treeSearch" ).keyup(function() {

       var group_nodes = $('.treeNodeText:contains("Client")').first().parent().parent().parent().find('.treeChildContainer').first().find('>.treeNode');
    
      var catalog_tree = [];
      group_nodes.each(function(){ 
        catalog_tree.push({'group':$(this).find('>.treeLine'), 'children':$(this).find('>.treeChildContainer .treeNode')});
      });

      var search_term = $( "#treeSearch" ).val().toUpperCase();
    
      catalog_tree.forEach(function(item){

        group = item.group;
        children = item.children;
        var group_count = 0;

        children.each(function(){
          var child = $(this);
          var label = child.find('.treeNodeText').text().toUpperCase();
          
          if (label.indexOf(search_term) > -1){
            child.css('display','block','important');
            group_count += 1
          }
          else{
            child.css('display','none','important');
          }
        });


        if (group_count > 0){
          group.css('display','block','important');
        }
        else{
          group.css('display','none','important');
        }

      });
    
    });
});